<template>
  <div class="infinite-container greenTop">
    <select-role2 @familychang="familychangHandle" :showCardNumber="false" :showAllCards="false"></select-role2>
    <confirm-id :familyPerson="familyPerson" :person="person" :show.sync="showCheck"></confirm-id>
    <div v-if="feeList.length > 0">
      <empty v-if = "isEmpty"></empty>
      <white-block v-else style="min-height:200px;">
        <mu-list slot="content">
          <template v-for="(value, index) in feeList">
            <mu-list-item :title="value.costDate" @click="toDetail(value)" :key="index">
              <span slot="right" class="feeTxt">{{value.costAmount | fixedMoney}}</span>
            </mu-list-item>
            <mu-divider v-show="index !== feeList.length - 1" :key="index"/>
          </template>
        </mu-list>
      </white-block>
    </div>
    <div class="not-found" v-else>
      <div>没有数据</div>
    </div>

    <p class="f12 text-center t3 pd10">提示：仅支持查询最近一年内门诊费用</p>
  </div>
</template>

<script>
  import SelectRole2 from '../../components/SelectRole2'
  import whiteBlock from '../../components/whiteBlock'
  import {commonAjax, RESTFUL_API} from '@/api/api'
  import empty from '@/components/empty'
  import confirmId from '../../components/confirmId'
  export default {
    data () {
      return {
        familyPerson: JSON.parse(sessionStorage.getItem('familyPerson')),
        person: JSON.parse(sessionStorage.getItem('person')),
        feeList: [],
        isEmpty: false,
        showCheck: false
      }
    },
    components: {
      SelectRole2, whiteBlock, empty, confirmId
    },
    mounted () {
      // this.$store.commit('UPDATE_LOADING')
    },
    methods: {
      checkAuth (val) {
        if (val.certificationValidityPeriod === '1') {
          this.queryMZFee()
        } else {
          this.showCheck = true
          this.feeList = []
        }
      },
      familychangHandle (f) {
        this.familyPerson = f
        this.queryMZFee()
      },
      toDetail (param) {
        this.$router.push({
          path: '/mainFeeRecord/detail',
          query: param
        })
      },
      queryMZFee () {
        this.$store.commit('UPDATE_LOADING')
        let param = {
          patientMedicalCardType: 1,
          patientIdentityCardType: this.familyPerson.cardtype,
          patientIdentityCardNumber: this.familyPerson.idcard,
          patientCode: this.familyPerson.patientcode
        }
        if (this.familyPerson.listHisBusCard && this.familyPerson.listHisBusCard.length > 1) {
          let tempCode = []
          this.familyPerson.listHisBusCard.forEach(v => {
            tempCode.push(v.patientBusCardId)
          })
          param.patientCode = tempCode.join(',')
        }
        commonAjax(RESTFUL_API.mzFee, param, true).then(res => {
          this.$store.commit('UPDATE_LOADING', false)
          if (res.data.code === 1) {
            if (res.data.data.length > 0) {
              this.feeList = res.data.data
              this.isEmpty = false
            } else {
              this.isEmpty = true
              this.feeList = []
            }
          } else {
            this.$store.commit('UPDATE_TOAST', {message: res.data.message})
          }
        }).catch(res => {
          this.$store.commit('UPDATE_LOADING')
          this.$store.commit('UPDATE_TOAST', {message: '服务忙'})
        })
      }
    }
  }
</script>

<style scoped lang="less">
  @import "../../common/css/flex.css";
  @import "../../common/css/vars";
  .feeTxt{
    color:@color-normal;
    font-size:16px;
  }
</style>
